//
//  LGNormalClinicHeader.m
//  HeartDiseaseManage
//
//  Created by 1234 on 2024/8/2.
//

#import "LGNormalClinicHeader.h"

#define itemW  (Screen_W-viewPix(56))/4.0

@interface LGNormalClinicHeader()

/**   */
@property (nonatomic , strong)UIImageView *baseView;
/**   */
@property (nonatomic , strong)UILabel *patientTitle;
@property (nonatomic , strong)UILabel *patientLabel;
/**   */
@property (nonatomic , strong)UILabel *doctorTitle;
@property (nonatomic , strong)UILabel *doctorLabel;
/**   */
@property (nonatomic , strong)UILabel *typeTitle;
@property (nonatomic , strong)UILabel *typeLabel;

/**   */
@property (nonatomic , strong)UIButton *detailBtn;
/**   */
@property (nonatomic , strong)UIButton *reportBtn;
/**   */
@property (nonatomic , strong)UIButton *medicineBtn;
/**   */
@property (nonatomic , strong)UIButton *monitorBtn;

@end

@implementation LGNormalClinicHeader

- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        
        [self createSubView];
    }
    return self;
}

-(void)setBasicDic:(NSDictionary *)basicDic{
    _basicDic = basicDic;
    self.patientLabel.text = [NSString stringWithFormat:@"%@ %@ %@岁 %@",basicDic[@"realname"],basicDic[@"gender"],basicDic[@"age"],basicDic[@"hospital_bano"]];
}

-(void)setVisitDic:(NSDictionary *)visitDic{
    _visitDic = visitDic;
    self.doctorLabel.text = LGNSString(visitDic[@"visit_doctor"]);
    self.typeLabel.text = LGNSString(visitDic[@"visit_type"]);
}


-(void)itemButtonAciton:(UIButton *)sender{
    NSString *type = @"";
    if (sender == self.detailBtn) {
        type = @"detail";
    }else if (sender == self.reportBtn){
        type = @"report";
    }else if (sender == self.medicineBtn){
        type = @"medicine";
    }else if (sender == self.monitorBtn){
        type = @"monitor";
    }
    if (self.delegate && [self.delegate respondsToSelector:@selector(headViewButtonTouched:)]) {
        [self.delegate headViewButtonTouched:type];
    }
}

-(void)createSubView{
    [self addSubview:self.baseView];
    [self.baseView addSubview:self.patientTitle];
    [self.baseView addSubview:self.patientLabel];
    [self.baseView addSubview:self.doctorTitle];
    [self.baseView addSubview:self.doctorLabel];
    [self.baseView addSubview:self.typeTitle];
    [self.baseView addSubview:self.typeLabel];
    [self addSubview:self.detailBtn];
    [self addSubview:self.reportBtn];
    [self addSubview:self.medicineBtn];
    [self addSubview:self.monitorBtn];
    [self.doctorLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.doctorTitle);
        make.left.right.equalTo(self.patientLabel);
    }];
}

-(UIImageView *)baseView{
    if(!_baseView){
        _baseView = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"慢病复查-背景"]];
        _baseView.frame = CGRectMake(viewPix(12), viewPix(16), Screen_W-viewPix(32), viewPix(120));
    }
    return _baseView;
}

-(UILabel *)patientTitle{
    if(!_patientTitle){
        _patientTitle = [UILabel lableWithText:@"患者信息" colorString:@"#FFFFFF" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
        _patientTitle.frame = CGRectMake(viewPix(12), viewPix(12), viewPix(70), viewPix(23));
    }
    return _patientTitle;
}

-(UILabel *)patientLabel{
    if(!_patientLabel){
        _patientLabel = [UILabel lableWithText:@"" colorString:@"#FFFFFF" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _patientLabel.frame = CGRectMake(viewPix(92), kMinY(self.patientTitle.frame), Screen_W-viewPix(130), viewPix(23));
    }
    return _patientLabel;
}

-(UILabel *)doctorTitle{
    if(!_doctorTitle){
        _doctorTitle = [UILabel lableWithText:@"接诊医生" colorString:@"#FFFFFF" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
        _doctorTitle.frame = CGRectMake(viewPix(12), kMaxY(self.patientTitle.frame)+viewPix(14), viewPix(70), viewPix(23));
    }
    return _doctorTitle;
}

-(UILabel *)doctorLabel{
    if(!_doctorLabel){
        _doctorLabel = [UILabel lableWithText:@"" colorString:@"#FFFFFF" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:2];
//        _doctorLabel.frame = CGRectMake(viewPix(92), kMinY(self.doctorTitle.frame), Screen_W-viewPix(130), viewPix(23));
    }
    return _doctorLabel;
}

-(UILabel *)typeTitle{
    if(!_typeTitle){
        _typeTitle = [UILabel lableWithText:@"类型" colorString:@"#FFFFFF" textFont:LGFont(16) textAlignment:NSTextAlignmentLeft lines:1];
        _typeTitle.frame = CGRectMake(viewPix(12), kMaxY(self.doctorTitle.frame)+viewPix(14), viewPix(70), viewPix(23));
    }
    return _typeTitle;
}

-(UILabel *)typeLabel{
    if(!_typeLabel){
        _typeLabel = [UILabel lableWithText:@"" colorString:@"#FFFFFF" textFont:LGFontWeight(16, UIFontWeightMedium) textAlignment:NSTextAlignmentLeft lines:1];
        _typeLabel.frame = CGRectMake(viewPix(92), kMinY(self.typeTitle.frame), Screen_W-viewPix(130), viewPix(23));
    }
    return _typeLabel;
}

-(UIButton *)detailBtn{
    if(!_detailBtn){
        _detailBtn = [UIButton buttonWithTitle:@"患者档案" titleFont:LGFontWeight(15, UIFontWeightMedium) textColor:@"#282828" frame:CGRectMake(viewPix(16), kMaxY(self.baseView.frame)+viewPix(16), itemW, viewPix(52))];
        _detailBtn.backgroundColor = [UIColor colorWithString:@"#EBF0FC"];
        [_detailBtn addBorder:@"#CFDBF1" lineWidth:1 cornerRidus:5];
        [_detailBtn addTarget:self action:@selector(itemButtonAciton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _detailBtn;
}

-(UIButton *)reportBtn{
    if(!_reportBtn){
        _reportBtn = [UIButton buttonWithTitle:@"报告中心" titleFont:LGFontWeight(15, UIFontWeightMedium) textColor:@"#282828" frame:CGRectMake(kMaxX(self.detailBtn.frame)+viewPix(8), kMaxY(self.baseView.frame)+viewPix(16), itemW, viewPix(52))];
        _reportBtn.backgroundColor = [UIColor colorWithString:@"#EBF0FC"];
        [_reportBtn addBorder:@"#CFDBF1" lineWidth:1 cornerRidus:5];
        [_reportBtn addTarget:self action:@selector(itemButtonAciton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _reportBtn;
}

-(UIButton *)medicineBtn{
    if(!_medicineBtn){
        _medicineBtn = [UIButton buttonWithTitle:@"用药管理" titleFont:LGFontWeight(15, UIFontWeightMedium) textColor:@"#282828" frame:CGRectMake(kMaxX(self.reportBtn.frame)+viewPix(8), kMaxY(self.baseView.frame)+viewPix(16), itemW, viewPix(52))];
        _medicineBtn.backgroundColor = [UIColor colorWithString:@"#EBF0FC"];
        [_medicineBtn addBorder:@"#CFDBF1" lineWidth:1 cornerRidus:5];
        [_medicineBtn addTarget:self action:@selector(itemButtonAciton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _medicineBtn;
}

-(UIButton *)monitorBtn{
    if(!_monitorBtn){
        _monitorBtn = [UIButton buttonWithTitle:@"体征监测" titleFont:LGFontWeight(15, UIFontWeightMedium) textColor:@"#282828" frame:CGRectMake(kMaxX(self.medicineBtn.frame)+viewPix(8), kMaxY(self.baseView.frame)+viewPix(16), itemW, viewPix(52))];
        _monitorBtn.backgroundColor = [UIColor colorWithString:@"#EBF0FC"];
        [_monitorBtn addBorder:@"#CFDBF1" lineWidth:1 cornerRidus:5];
        [_monitorBtn addTarget:self action:@selector(itemButtonAciton:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _monitorBtn;
}

@end
